package leetcode.median;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;

import leetcode.base.TreeNode;

public class $513_FindBottomLeftValue {
    public int findBottomLeftValue(TreeNode root) {
        // 层序遍历
        Deque<TreeNode> deque = new LinkedList<>();
        int res = 0;
        deque.offerLast(root);
        while (!deque.isEmpty()) {
            int len = deque.size();
            for (int i = 0;i < len;i++) {
                TreeNode treeNode = deque.pollFirst();
                if (i == 0) {
                    res = treeNode.val;
                }
                if (treeNode.left != null) {
                    deque.offerLast(treeNode.left);
                }
                if (treeNode.right != null) {
                    deque.offerLast(treeNode.right);
                }
            }
        }
        return res;
    }
}
